package com.chl.legou.security.controller;

import com.chl.legou.core.controller.BaseController;
import com.chl.legou.security.po.Role;
import com.chl.legou.security.po.User;
import com.chl.legou.security.service.IRoleService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author chlong
 * @date 2022/1/16
 */

@RestController
@RequestMapping("/role")
public class RoleController extends BaseController<IRoleService, Role> {

    @Override
    public void afterEdit(Role entity) {
        //生成用户列表, 如：1,3,4
        List<User> users = service.selectUserByRole(entity.getId());
        Long[] ids = new Long[users.size()];
        for (int i = 0; i < users.size(); i++) {
            ids[i] = users.get(i).getId();
        }
        entity.setUserIds(ids);
    }
}
